home *** CD-ROM | disk | FTP | other *** search
- // pixel shader to combine shadow map texture with model drawing to create shadows
- // used when drawing objects
-
- ps_2_0 // version
- dcl t0.xyzw // lookup object texel using this coordinate
- dcl t1.xyzw // lookup texel on shadowmap using this coordinate
- dcl t2.x // z from light point of view
- dcl v0.rgba // input color
- dcl_2d s0 // object texture
- dcl_2d s1 // shadow map texture
-
- // sample center point and three other nearby points and average the results
- def c0, 0.00087891, 0, 0,0 // point 2
- def c1, -0.00043945, 0.00076116, 0,0 // point 3
- def c2, -0.00043945, -0.00076116, 0,0 // point 4
- def c3, 0.25,0.25,0.25,0.25 // factor
- // c16 defined by app: 1-shadowalpha, 1.0f, zbias, unused
-
- add r1,t1,c0
- add r2,t1,c1
- add r3,t1,c2
-
- texld r0, t1, s1 // get point 1 from shadow map
- texld r1, r1, s1 // get point 2 from shadow map
- texld r2, r2, s1 // get point 3 from shadow map
- texld r3, r3, s1 // get point 4 from shadow map
-
- // add r4.r,t2.x,c16.z // get z from vertex shader and add zbias
- mov r4.r,t2.x // added z-bias in vertex shader
-
- sub r0.r,r0.r,r4.r
- sub r0.g,r1.r,r4.r
- sub r0.b,r2.r,r4.r
- sub r0.a,r3.r,r4.r
- cmp r5,r0,c16.y,c16.x // r5 = results of the comparisons with all the points
- dp4 r6,r5,c3 // average the result
- mov r6.a,c16.y // shadow alpha = 1.0 (ie shadow doesn't reduce alpha)
-
- texld r0, t0, s0 // get the texel from the object texture
- mul r0,r0,v0 // combine with input color
- mul r0,r0,r6 // combine with shadow
- mov oC0,r0 // move resulting color to output
-
-